$(function () {
    const socket = io('/');
    socket.on('connect', () => {
        console.log(socket.id)
    })
    socket.on('res', (data) => {

        if (data.load == "suc") {
            console.log(data);
            let userName = data.user.account
            console.log(userName);
            localStorage.setItem(userName, data.user)
            document.location.href = `/index.html?user=${userName}`
        } else if (data.load == "err") {
            console.log('err');
            alert("账户或密码错误")
        }
    })

    socket.on('connect_error', err => {
        socket.disconnect()
        console.log('connect_error', err)
    })

    $("button[name='submit']").click(function () {
        console.log('1');
        
        socket.emit('login', {
            userName: $('#userName').val(),
            pwd: $("#pwd").val()
        })
    })
    window.socket = socket;


})